﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Manage/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<RuiJing.Web.Areas.Manage.Models.ProductModels.IndexModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	产品管理
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% Html.BeginForm("index", "product", new { id = "productform" }, new { Model.ID, S = (Model.S ?? false) ? "" : "True" }); %>
<div class="typepath">
    <%=Html.ActionLink("产品管理:", "index", new { S = (Model.S ?? false) ? "" : "True" })%>
    <% foreach (var item in Model.Parents) %>
    <% { %>
    &nbsp;&gt;&nbsp;
    <%=Html.ActionLink(item.Name_Ch, "index", new { S = (Model.S ?? false) ? "" : "True", id = item.ID }, new { title = item.Name_En }) %>
<% } %>
</div>
<div class="typechilds">
    <ul>
        <% foreach (var item in Model.Childs) %>
        <% { %>
        <li><%=Html.ActionLink(string.Format("{0}({1})", item.Name_Ch, item.ProductCount), "index", new { id = item.ID, S = (Model.S ?? false) ? "" : "True" }, new { title = item.Name_En })%></li>
        <% } %>
    </ul>
</div>
<div class="producttop">
<table width="100%">
    <tr>
        <% this.ViewContext.RouteData.Values.Remove("S"); %>
        <td><%=Html.ActionLink("新增产品", "add", new { id = Model.ID })%></td>
        <td>
             <% var tmp = !(Model.S ?? false) ? "checked='checked'" : "";  %>
            <label><input type="checkbox" <%=tmp %> onclick="location.href='<%=Url.Action("index", new { S = !(Model.S ?? false) ? "" : "True", Model.ID }) %>'" />当前下级</label>
        </td>
        <td><label><input type="checkbox" onclick="chooseID(this)" />选中所有</label></td>
        <td><input type="submit" name="DelMore" value="删除选中" onclick="if($('.pruductlist #ChooseID:checked').length==0) { alert('请先选中要删除的产品！') ; return false; }" /></td>
        <td><input type="button" name="Move" value="移动选中" onclick="moveProduct()" /></td>
    </tr>
</table>
</div>
<div class="pruductlist">
    <% foreach (var item in Model.Products) %>
    <% { %>
    <div class="picitem">  
        <div class="picimg">
        <a href='<%=item.DefaultPic %>' target="_blank" title='<%=item.Name_Ch %>(<%=item.Name_En %>)<%=string.IsNullOrEmpty(item.TypePath) ? "" : "\r\n" + Html.Encode(item.TypePath) %>'>
            <img class="img" src='<%=item.DefaultPic %>' alt='' />
        </a>
        </div>
        <div class="picname">
        <a href='<%=Url.Action("edit", new { id=item.ID})%>' title='<%=item.Name_Ch %>(<%=item.Name_En %>)'><%=item.Number %>(编辑)</a>
        <input type="checkbox" id="ChooseID" name="ChooseID" value='<%=item.ID %>' />
        <%=Html.ActionLink("删除", "del" , new { id = Model.ID, a = item.ID }, new { onclick="return confirm('您确定要删除该产品吗？');"})%>
        </div>
    </div> 
    <% } %>
    <% if (Model.SumCount > 0) %>
    <% { %>
    <div class="pager">
        <%=Html.Pager(Model.A, Model.B, 12, Model.SumCount, "a", Url.Route(new { Model.ID, serch = Model.Serch, S = (Model.S ?? false) ? "" : "True" }), "b")%>
    </div>
    <% } %>
    <input type="hidden" id="btnAction" name="" />
</div>
<% Action<IEnumerable<ProductType>,ProductType> PutTree = null; PutTree=((d,n) =>%>
<% { %>
    <% if (n != null) %>
    <% { %>
    <div class="trre_item-head">
        <span class="trre-icon trre-plus"></span>
        <span class="trre-in">
            <%=n.Name_Ch%>(<%=n.Name_En%>)
            <input type="hidden" id="hidden_id" value='<%=n.ID %>'/>
        </span>
    </div>
    <% }%>
    <% else %>
    <% { %>
    <div class="trre-content">
    <% } %>
    <ul class="trre-group">
    <%
    int? id = n == null ? null as int? : n.ID;
    var items = d.Where(p => p.ParentID == id);
    foreach (var item in items)
    {
    %>
        <li class="trre-item">
            <% PutTree(d,item); %>
        </li>
    <%
    }
    %>
    </ul>
    <% if (n != null) %>
    <% { %>
    <% }%>
    <% else %>
    <% { %>
    </div>
    <% } %>
<% }); %>
<div class="dialog">
<div class="trre-set">
    <% PutTree(Model.Types,null); %>
</div>
</div>
<% Html.EndForm(); %>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="StypeAndScript" runat="server">
    <script src='<%=Url.Content("~/Scripts/tool/trre-view.js") %>' type="text/javascript"></script>
    <link href='<%=Url.Content("~/Scripts/tool/ui.css") %>'  rel="stylesheet" type="text/css" />
    <style type="text/css">
    .typepath{ width:100%; line-height:30px; }
    .producttop{ width:100%; line-height:30px; }
    .typechilds { border-bottom:1px solid #888;}
    .typechilds,.typechilds ul{ height:auto; overflow:hidden; width:100%; }
    .typechilds li{ height:25px; padding:3px 5px; width:100px; text-align:center; float:left;}
    .pruductlist{width:100%; height:auto; overflow:hidden;}
    .pager{ width:100%; float:left; text-align:center;}
    .trre-content{border:1px solid #c3c3c3; margin:10px;padding:10px;line-height:25px;}
    .trre-set{width:500px;}
    .dialog{ display:none;}
</style>
    <script type="text/javascript">
        function chooseID(c) {
            $('.pruductlist #ChooseID').each(function () {
                this.checked = c.checked;
            });
        }

        function moveProduct() {
            if ($('.pruductlist #ChooseID:checked').length == 0) {
                alert('请先选中要移动的产品！'); 
                return;
            }
            $.blockUI({ message: null });
            var g =
            {
                closeText: '取消',
                title: '选择分类',
                width: '500px',
                height: 'auto',
                beforeClose: function () {
                    $.unblockUI();
                },
                buttons: {
                    "取消": function () {
                        $(this).dialog('close');
                    },
                    "确定": function () {
                        var item = $(".trre-content .trre-state-selected");
                        var typeid = item.find("#hidden_id").val();
                        if (isNaN(typeid)) {
                            alert("请选择所属分类！")
                            return;
                        }
                        $("#btnAction").attr("name", "Move:" + typeid);
                        $("#productform").submit();
                        $(this).dialog('close');
                    }
                }
            };
            $(".dialog").dialog(g);
        }
    </script>
</asp:Content>
